# coding:utf-8
import os

root_path = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
import sys

sys.path.append(root_path)
from config import *
import pytest
import time


def run():
    test_path = pro_path + r"\testcase_saas"

    date = time.strftime('%Y-%m-%d')
    localtime = time.strftime('%Y%m%d%H%M%S', time.localtime())
    file_path = report_path + date + "/" + localtime + "/"
    date_path = report_path + date + "/"
    temporary_report_path = temps_path + localtime + "/"

    isExists1 = os.path.exists(date_path)
    isExists2 = os.path.exists(file_path)
    isExists3 = os.path.exists(temporary_report_path)
    if not isExists1:
        os.mkdir(date_path)
    if not isExists2:
        os.mkdir(file_path)
    if not isExists3:
        os.mkdir(temporary_report_path)

    # 执行pytest单元测试，生成 Allure 报告需要的数据存在 /temp 目录
    pytest.main(['-s', '-q', '{0}'.format(test_path), '--alluredir', temporary_report_path,'--show-capture=no'])
    # 执行命令 allure generate ./temp -o ./report --clean ，生成测试报告
    # os.system(r'allure generate {0} -o {1} '.format(temporary_report_path, file_path))
    # os.system(r'allure serve {0}'.format(temporary_report_path))


if __name__ == "__main__":
    run()
